## DESCRIPTION
## Differential Equations: adding the Heaviside function to the context.
## ENDDESCRIPTION

## KEYWORDS('differential equations', 'adding the Heaviside function to the context')

## DBsubject('WeBWorK')
## DBchapter('WeBWorK Tutorial')
## DBsection('Fort Lewis Tutorial 2011')
## Date('01/30/2011')
## Author('Paul Pearson')
## Institution('Fort Lewis College')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')


###########################
#  Initialization

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"parserFunction.pl",
);

TEXT(beginproblem());


###########################
#  Setup

Context("Numeric");
Context()->variables->are(t=>"Real");
Context()->functions->add(
  step => {
    class => 'Parser::Legacy::Numeric',
    perl => 'Parser::Legacy::Numeric::do_step'
  },
);

$a = 3;

$ftex  = "5 u(t-$a)";

$fstep = Formula("5*step(t-$a)");

$answer1 = List($fstep->eval(t=>2),$fstep->eval(t=>3),$fstep->eval(t=>4));


###########################
#  Main Text

Context()->texStrings;
BEGIN_TEXT
Let \( u(t) \) be the Heaviside step function 
defined by
\( \displaystyle
u(t) =
\left\lbrace
\begin{array}{lcl}
0 && \mbox{ if } x \leq 0, \\
1 && \mbox{ if } x > 0.
\end{array}
\right.
\)
$BR
$BR
(a) Evaluate the function \( $ftex \) when  
\( t \) is \(2\), \(3\), and \(4\) and enter 
your answers as a comma separated list.
$BR
\{ ans_rule(20) \}
\{ AnswerFormatHelp("numbers") \} 
END_TEXT
Context()->normalStrings;


############################
#  Answer Evaluation 1

$showPartialCorrectAnswers=1;

ANS( $answer1->cmp(ordered=>1) );


############################
#  Setup 2

Context("Numeric");
Context()->variables->are(t=>"Real");
Context()->functions->add(
  step => {
    class => 'Parser::Legacy::Numeric',
    perl => 'Parser::Legacy::Numeric::do_step'
  },
);

parserFunction("u(t)" => "step(t)");
$f = Formula("5 u(t-$a)");

$answer2 = $f->with(
  limits=>[$a-5,$a+5], 
  test_at => [[$a-1],[$a],[$a+0.0000001],[$a+1]],
  num_points=>10,
);


############################
#  Main text 2

Context()->texStrings;
BEGIN_TEXT
$BR
$BR
(b) Suppose the answer is the function \( $ftex \).
$BR
\{ ans_rule(20) \}
\{ AnswerFormatHelp("formulas") \} 
END_TEXT
Context()->normalStrings;


#############################
#  Answer evaluation 2

ANS( $answer2->cmp() );


############################
#  Solution

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();
